<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Class Main extends MY_Controller
 * ----------------------------------------------------------
 * Author:		Michael Lamb
 * Date:		February 2012
 * Version:		0.1
 * 
 * ----------------------------------------------------------
 * Synopsis:
 * ---------
 * Public CMS content controller
 * 
 * This class is only invoked when
 * there are has been no other
 * can be saught
 *
 *	Returns a 404 if no page in the
 *	database can be found
 *
 * ----------------------------------------------------------
 * Methods:
 * --------
 * index		Loads CMS pages
 * exhibitions 	Loads exhibition data - News in full CMS
 * ----------------------------------------------------------
 * Planned Changes:
 * -----------------
 * - Remove smarty template system in replacement of CI based
 *   templating
 * 
 * ----------------------------------------------------------
 * Version History:
 * -----------------
 * 0.1
 * ----------------
 * - Make use of smarty templating system;
 * - Grab menu data from database
 * - Load CMS page based on passed data, load home page if
 *   no data is passed
 *   
 * ----------------------------------------------------------
 * ##########################################################
 * ----------------------------------------------------------
 */
class Main extends MY_Controller {
	/**
	 * Name:	index
	 * Scope:	Public
	 * 
	 * @params:
	 * 		$page - string
	 * 		$params - array
	 */
	public function index($page='home', $params=array())
	{
		$this->load->model('site_model');
		
		//Build the main menu and assign to the template
		$params = array('menu' => 'main');
		$menu = $this->site_model->getMainMenu($params);
		$this->smarty->assign('menu',$menu);
		
		//Get page details and pass to the template or show 404 error
		$content = $this->site_model->getPageContent($page);
		if(!$content)
		{
			show_404();
		}
		$this->smarty->assign('content',$content);
		
		//Push the page to the browser
		$this->smarty->view('main.tpl');
	}
	
	/**
	 * Name:	exhibitions
	 * Scope:	Public
	 * 
	 * @params:
	 * 		$params - array
	 */
	public function exhibitions($exhibition = FALSE)
	{
		//Load required modules
		$this->load->model('site_model');
		$this->load->model('news_model');
		
		
		
		//Build the main menu and assign to the template
		$params = array('menu' => 'main');
		$menu = $this->site_model->getMainMenu($params);
		$this->smarty->assign('menu',$menu);
		
		// Get the news page details
		$meta = $this->site_model->getPageContent('exhibitions');
		$this->smarty->assign('meta',$meta);
		
		if($exhibition)
		{	//Get selected exhibition data
			$article = array('article', $exhibition);
			$article = $this->news_model->getArticle($exhibition);
			$this->smarty->assign('article',$article);
			
			//Push the page to the browser
			$this->smarty->view('exhibition.tpl');
		}
		else
		{ 	//Get all exhibitions
			$articles = $this->news_model->getAll();
			if($articles)
			{
				$this->smarty->assign('articles',$articles);
			}
			else
			{
				$error->title = 'Exhibitions';
				$error->excerpt = 'Sorry there are no exhibitions to display at this time';
				$error->date = '';
				$errors = array();
				array_push($errors,$error);
				
				$this->smarty->assign('articles', $errors);
			}
			//Push the page to the browser
			$this->smarty->view('exhibition_list.tpl');
		}
	}
	
	/**
	 * Name:	contact
	 * Scope:	Public
	 * 
	 * @params:
	 * 		$params - array
	 */
	public function contact()
	{
		$this->load->helper(array('form', 'url'));
		$this->load->library('form_validation');
		
		
		if ($this->form_validation->run() == FALSE)
		{
			$this->smarty->view('contact');
		}
		else
		{
			$this->smarty->view('contact_success');
		}
		
	}
}
/* End of file main.php */
/* Location: ./application/controllers/main.php */